/**
 * @author   thienchau
 * @time     1:08:58 PM Jan 31, 2013
 * @filename AlertHelper.java
 */

package com.cdn.allmobilestore.ulti;

import com.cdn.allmobilestore.R;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnCancelListener;
import android.content.Intent;
import android.provider.Settings;


public class AlertHelper {
	public static final int MAX_CHAR_REASON = 140;
	public static String textFromEdit = "";

	public static String getTextFromEdit() {
		return textFromEdit;
	}

	public static void setTextFromEdit(String s) {
		textFromEdit = s;
	}

	public static void showMessageAlert(Context context, String message) {
		if (!Ulti.isOnTop((Activity) context)) {
			return;
		}

		AlertDialog.Builder alertbox = new AlertDialog.Builder(context);
		// alertbox.setTitle("Message");
		alertbox.setMessage(message);

		alertbox.setPositiveButton(R.string.OK,
				new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int arg1) {
						dialog.dismiss();
					}
				});

		alertbox.show();
	}

	public static void showMessageAlert(Context context, String message,
			DialogInterface.OnClickListener listener) {

		if (!Ulti.isOnTop((Activity) context)) {
			return;
		}

		AlertDialog.Builder alertbox = new AlertDialog.Builder(context);
		// alertbox.setTitle("Message");
		alertbox.setMessage(message);
		alertbox.setCancelable(false);
		alertbox.setPositiveButton(R.string.OK, listener);

		alertbox.show();
	}

	public static void showMessageAlertOKCancel(Context context, String title,
			String message, DialogInterface.OnClickListener listenerOk,
			DialogInterface.OnClickListener listenerCancel) {

		if (!Ulti.isOnTop((Activity) context)) {
			return;
		}

		AlertDialog.Builder alertbox = new AlertDialog.Builder(context);
		alertbox.setTitle(title);
		alertbox.setMessage(message);
		alertbox.setCancelable(false);
		alertbox.setPositiveButton(R.string.OK, listenerOk);
		alertbox.setNegativeButton(R.string.Cancel, listenerCancel);
		alertbox.show();
	}

	public static void showMessageAlertOKCancel(Context context,
			String message, DialogInterface.OnClickListener listenerOk,
			DialogInterface.OnClickListener listenerCancel) {

		/*if (!Ulti.isOnTop((Activity) context)) {
			return;
		}*/

		AlertDialog.Builder alertbox = new AlertDialog.Builder(context);
		// alertbox.setTitle("Message");
		alertbox.setMessage(message);
		alertbox.setCancelable(false);
		alertbox.setPositiveButton(R.string.OK, listenerOk);
		alertbox.setNegativeButton(R.string.Cancel, listenerCancel);
		alertbox.show();
	}

	public static void showMessageAlertOK(Context context,
			DialogInterface.OnClickListener listener, String message,
			String button1) {

		/*if (!Ulti.isOnTop((Activity) context)) {
			return;
		}*/

		AlertDialog.Builder alertbox = new AlertDialog.Builder(context);
		// alertbox.setTitle(tittle);
		alertbox.setMessage(message);

		alertbox.setPositiveButton(button1, listener);
		alertbox.show();
	}

	public static void showMessageAlert(Context context, String title,
			String message, DialogInterface.OnClickListener onclickListener) {

		if (!Ulti.isOnTop((Activity) context)) {
			return;
		}

		AlertDialog.Builder alertbox = new AlertDialog.Builder(context);
		alertbox.setTitle(title);
		alertbox.setMessage(message);
		alertbox.setPositiveButton(R.string.OK, onclickListener);
		alertbox.show();
	}

	public static void showMessageAlert(Context context, String title,
			String message) {

		if (!Ulti.isOnTop((Activity) context)) {
			return;
		}

		AlertDialog.Builder alertbox = new AlertDialog.Builder(context);
		alertbox.setTitle(title);
		alertbox.setMessage(message);

		alertbox.setPositiveButton(R.string.OK,
				new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int arg1) {
						dialog.dismiss();
					}
				});

		alertbox.show();
	}

	public static void showMessageAlert(Context context,
			DialogInterface.OnClickListener listener, String message,
			String button1, String button2) {

		if (!Ulti.isOnTop((Activity) context)) {
			return;
		}
		AlertDialog.Builder alertbox = new AlertDialog.Builder(context);
		alertbox.setTitle("");
		alertbox.setMessage(message);

		alertbox.setPositiveButton(button1, listener);
		alertbox.setNegativeButton(button2, listener);
		alertbox.show();
	}

	public static void showMessageAlert(Context context,
			DialogInterface.OnClickListener listener, String tittle,
			String message, String button1, String button2) {
		if (!Ulti.isOnTop((Activity) context)) {
			return;
		}
		AlertDialog.Builder alertbox = new AlertDialog.Builder(context);
		alertbox.setTitle(tittle);
		alertbox.setMessage(message);

		alertbox.setPositiveButton(button1, listener);
		alertbox.setNegativeButton(button2, listener);
		alertbox.show();
	}

	public static void showMessageAlert(Context context, String tittle,
			String message, String button1, String button2,
			DialogInterface.OnClickListener listener1,
			DialogInterface.OnClickListener listener2) {
		if (!Ulti.isOnTop((Activity) context)) {
			return;
		}
		AlertDialog.Builder alertbox = new AlertDialog.Builder(context);
		alertbox.setTitle(tittle);
		alertbox.setMessage(message);

		alertbox.setPositiveButton(button1, listener1);
		alertbox.setNegativeButton(button2, listener2);
		alertbox.show();
	}

	// catch even close dialog
	public static void showMessageAlert1(Context context, String tittle,
			String message, String button1, String button2,
			DialogInterface.OnClickListener listener1,
			DialogInterface.OnClickListener listener2,
			OnCancelListener onCancelListener) {
		if (!Ulti.isOnTop((Activity) context)) {
			return;
		}
		AlertDialog.Builder alertbox = new AlertDialog.Builder(context);
		alertbox.setTitle(tittle);
		alertbox.setMessage(message);
		alertbox.setOnCancelListener(onCancelListener);
		alertbox.setPositiveButton(button1, listener1);
		alertbox.setNegativeButton(button2, listener2);
		alertbox.show();
	}

	public static void showMessageAlertGPS(final Context context,
			String tittle, String message, String button1, String button2) {
		if (!Ulti.isOnTop((Activity) context)) {
			return;
		}
		AlertDialog.Builder alertbox = new AlertDialog.Builder(context);
		alertbox.setTitle(tittle);
		alertbox.setMessage(message);

		alertbox.setNegativeButton(button2,
				new DialogInterface.OnClickListener() {

					@Override
					public void onClick(DialogInterface dialog, int which) {
						// TODO Auto-generated method stub
						dialog.dismiss();
						Intent intent = new Intent(
								Settings.ACTION_LOCATION_SOURCE_SETTINGS);
						context.startActivity(intent);

					}
				});
		alertbox.setPositiveButton(button1,
				new DialogInterface.OnClickListener() {

					@Override
					public void onClick(DialogInterface dialog, int which) {
						// TODO Auto-generated method stub
						dialog.dismiss();
					}
				});

		alertbox.show();
	}

	public static void showMessageAlertSupportVersion(Context context,
			DialogInterface.OnClickListener listener,
			DialogInterface.OnCancelListener dismis, String tittle,
			String message, String button1, String button2) {
		if (!Ulti.isOnTop((Activity) context)) {
			return;
		}
		AlertDialog.Builder alertbox = new AlertDialog.Builder(context);
		alertbox.setTitle(tittle);
		alertbox.setMessage(message);

		alertbox.setPositiveButton(button1, listener);
		if (button2.length() > 0) {
			alertbox.setNegativeButton(button2, listener);
		}
		alertbox.setOnCancelListener(dismis);
		alertbox.show();
	}

	public static void showMessageAlertUnsupportVersion(Context context,
			DialogInterface.OnClickListener listener, String tittle,
			String message, String button1, String button2) {
		if (!Ulti.isOnTop((Activity) context)) {
			return;
		}
		AlertDialog.Builder alertbox = new AlertDialog.Builder(context);
		alertbox.setTitle(tittle);
		alertbox.setMessage(message);
		alertbox.setPositiveButton(button1, listener);
		if (button2.length() > 0) {
			alertbox.setNegativeButton(button2, listener);
		}
		alertbox.show();
	}

	public static void showMessageAlertWithIcon(Context context,
			DialogInterface.OnClickListener listener, String tittle,
			String message, String button1, String button2) {
		if (!Ulti.isOnTop((Activity) context)) {
			return;
		}
		AlertDialog.Builder alertbox = new AlertDialog.Builder(context);
		alertbox.setTitle(tittle);
		alertbox.setIcon(context.getResources().getDrawable(
				R.drawable.ic_launcher));
		alertbox.setMessage(message);

		alertbox.setPositiveButton(button1, listener);
		alertbox.setNegativeButton(button2, listener);
		alertbox.show();
	}

	public static void showMessageAlert(Context context, int stringResourceId,
			String buttonText) {
		if (!Ulti.isOnTop((Activity) context)) {
			return;
		}
		AlertDialog.Builder alertbox = new AlertDialog.Builder(context);
		alertbox.setTitle("Message");
		alertbox.setMessage(context.getResources().getString(stringResourceId));

		alertbox.setPositiveButton(buttonText,
				new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int arg1) {
						dialog.dismiss();
					}
				});
		alertbox.show();
	}
}
